package logic

import (
	"context"
	"fmt"
	"novel/model/mysql"

	"novel/novelrpc/internal/svc"
	"novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectShowLogic {
	return &CollectShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 小说喜欢详情
func (l *CollectShowLogic) CollectShow(in *novelrpc.CollectShowRequest) (*novelrpc.CollectShowResponse, error) {
	// todo: add your logic here and delete this line
	var collect mysql.Collect
	mysql.DB.Where("id=?", in.CollectId).Find(&collect)
	if collect.ID == 0 {
		return nil, fmt.Errorf("该收藏的小说不存在")
	}

	return &novelrpc.CollectShowResponse{
		UserId:      collect.UserId,
		BookId:      collect.BookId,
		CollectName: collect.CollectName,
	}, nil
}
